import { Robot, Group, Resource } from "leafer-game";
import { Bounds } from "leafer-ui";
import { registerUI, Leafer } from "@leafer-ui/core";
import { Collider } from '../collider';
import type { IGroupInputData } from '@leafer-ui/interface';
import type { Collidable } from "../interface/collidable";
const url = '/Outdoor_decoration/Oak_Tree.png'

@registerUI()
export class Tree extends Group implements Collidable {
    trees: Robot[] = [];
    collider: Collider;
    power = 100;
    constructor(data: IGroupInputData) {
        super(data)
        this.collider = new Collider({
            width: 42,
            height: 30,
            offsetX: 10,
            offsetY: 45,
            colloderInfo: {
                type: 'static',
                instance: this
            }
        })
        Resource.loadImage(url).then(() => {
            const Oak_Tree = new Robot({
                robot: { url, size: { width: 64, height: 80 }, total: 1 },
                actions: {
                    default: [0],
                },
                action: 'default', // 设置默认动作
            })
            this.trees.push(Oak_Tree);
            super.add([...this.trees, this.collider]);
        })

    }
    onHit(collider: Collidable): void {
        console.log(collider)
    }

    get bounds() {
        return new Bounds(this.collider.worldBoxBounds);
    }
}